/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package newpackage;
/**
 *
 * @author BATAQUERO
 */
public class algoritmo_BoyerMoore extends Busqueda{
public static int validar;

public static void algoritmoBM(String compararBM){

        validar=Comparar(compararBM, LongitudTexto);
        if(validar!=-1){
        MostrarResultados(compararBM);
        TotalCoincidencias++;
        }   
}
public static int Comparar(String text, String pattern){
    int[] last = buildLastFunction(pattern);
       int i = pattern.length() -1;
       if (i > text.length() - 1)
         return -1;
       int j = pattern.length() - 1;
       do {
            if (pattern.charAt(j) == text.charAt(i)){
                    if (j == 0){
                        return i;
                    }
                    else { i--; j--; }}

             else {
                    i = i + pattern.length() - Math.min(j, 1 + last[text.charAt(i)]); j = pattern.length() - 1;
             }
       } while (i <= text.length() - 1);
       return -1;
 }

       public static int[] buildLastFunction (String texto) {
       int[] last = new int[128];
       for (int i = 0; i < 128; i++) {
         last[i] = -1;
       }
       for (int i = 0; i < texto.length(); i++) {
         last[texto.charAt(i)] = i;
       }
       return last;
        }
}
